if __name__ == '__main__':
    import pandas as pd

    # df = pd.read_csv(r"D:\家宽\综资\综资数据(更新至2025年7月8日)\20250708171831_CONNECT_POS.csv", encoding="ANSI",
    #                  usecols=['POS级别', '所属分纤箱'])
    # df = df.astype(str).apply(lambda x: x.str.lstrip('\t'))
    #
    # grouped = df.groupby('所属分纤箱')['POS级别'].unique()
    #
    #
    # # Step 2: Define a function to determine the fiber box type based on POS levels
    # def determine_fiber_box_type(pos_levels):
    #     # Remove duplicates and sort for consistency
    #     unique_levels = sorted(set(pos_levels))
    #
    #     if len(unique_levels) == 1:
    #         # Only one type - append "分纤箱" to the POS level
    #         return f"{unique_levels[0]}分纤箱"
    #     else:
    #         # Multiple types - join them with "+" and append "分纤箱"
    #         joined_levels = "+".join(unique_levels)
    #         return f"{joined_levels}分纤箱"
    #
    #
    # # Step 3: Apply the function to each group
    # result = grouped.apply(determine_fiber_box_type).reset_index()
    # result.columns = ['所属分纤箱', '分纤箱类型']
    #
    # # Display the result
    # result.to_csv(r"D:\家宽\综资\分纤箱类型分类结果.csv",index=False)
    t = pd.read_csv('/temp/t.csv', encoding='GBK')
    df = pd.read_csv(r"D:\家宽\综资\合并.csv")
    t = t.merge(df, on='所属分纤箱', how='left')
    t.to_excel("/temp/t.xlsx")
